package com.jiutong.meipenggang.ui.activitys;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiutong.meipenggang.R;
import com.jiutong.meipenggang.base.BaseActivity;
import com.jiutong.meipenggang.entity.ServiceAgreementBean;
import com.jiutong.meipenggang.http.model.interfaces.BaseBiz;
import com.jiutong.meipenggang.http.present.ServiceAgreementPresent;
import com.jiutong.meipenggang.views.x5webview.X5WebView;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 作用:
 * Created by 78 on 2017/6/19.
 */
public class AgreementActivity extends BaseActivity implements BaseBiz {

    @Bind(R.id.tv_common_title)
    TextView tv_title;
    @Bind(R.id.wv_agreement)
    X5WebView wv_agreement;
    @Bind(R.id.rl_common_title_back)
    RelativeLayout rlCommonTitleBack;

    private ServiceAgreementPresent serviceAgreementPresent;

    @Override
    public int getLayoutResouceId() {
        return R.layout.activity_agreement;
    }

    @Override
    protected void initView() {
        super.initView();
        tv_title.setText("服务协议");
        serviceAgreementPresent = new ServiceAgreementPresent(this,this);
        serviceAgreementPresent.serviceAgreement();
    }

    @OnClick({R.id.rl_common_title_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_common_title_back:
                finish();
                break;
        }
    }

    @Override
    public void onSuccess(Object object) {
        ServiceAgreementBean bean = (ServiceAgreementBean) object;
        if(bean.getError()==-1){
            wv_agreement.loadDataWithBaseURL(null,bean.getContent(),"text/html", "utf-8",null);
        }else{
            toastShortShow(bean.getMsg());
        }
    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public int getOpt() {
        return 2;
    }

    @Override
    protected void onDestroy() {
        if(wv_agreement!=null){
            wv_agreement.destroy();
        }
        super.onDestroy();
    }
}
